﻿<%@ Page Language="C#" MasterPageFile="~/Game/Game.Master" AutoEventWireup="true" CodeBehind="Messages.aspx.cs" Inherits="smallDeimos.Game.Messages" Title="Personal messages" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        AutoGenerateColumns="False" DataKeyNames="MessageId" 
        DataSourceID="ObjectDataSource1" Width="700px">
        <Columns>
            <asp:BoundField DataField="Sent" HeaderText="Sent" SortExpression="Sent">
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
            </asp:BoundField>
            <asp:BoundField DataField="From" HeaderText="From" ReadOnly="True" 
                SortExpression="From" />
            <asp:BoundField DataField="To" HeaderText="To" ReadOnly="True" 
                SortExpression="To" />
            <asp:BoundField DataField="Message" HeaderText="Message" 
                SortExpression="Message" HtmlEncode="False" />
            <asp:CommandField ShowDeleteButton="True">
                <ItemStyle Width="75px" />
            </asp:CommandField>
        </Columns>
        <EmptyDataTemplate>
            You have no messages.
        </EmptyDataTemplate>
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        DeleteMethod="DeleteMessage" SelectMethod="GetMessagesForPlayer" 
        TypeName="SD.Database.DataAccess">
        <DeleteParameters>
            <asp:Parameter Name="MessageId" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:CookieParameter CookieName="sd_id" Name="pId" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:smallDeimosConnectionString %>" 
        DeleteCommand="Delete from Messages Where MessageId = @MessageId" 
        SelectCommand="SELECT MessageId, (SELECT PlayerName FROM Players WHERE (PlayerId = Messages.[From])) AS [From], (SELECT PlayerName FROM Players AS Players_1 WHERE (PlayerId = Messages.[To])) AS [To], Message, Sent FROM Messages WHERE ([To] = @to )">
        <SelectParameters>
            <asp:CookieParameter CookieName="sd_id" Name="to" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="MessageId" />
        </DeleteParameters>
    </asp:SqlDataSource>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        Text="Write new message" />
</asp:Content>
